/**
 * Created by 王健 on 2018/4/12.
 */
$(function () {

    var html_data = {
        baseConfig: baseConfig,
        sessionid: '',
        sessionid_q: '',
        un_dispute_page_index: 0,
        un_dispute_page_count: 0,
        doing_dispute_page_index: 0,
        doing_dispute_page_count: 0,
        finish_dispute_page_index: 0,
        finish_dispute_page_count: 0,
        dispute_orderinfo: {},
        goods_order_item: [],
        un_dispute_order_list: [], //未处理售后
        doing_dispute_order_list: [], //未处理售后
        finish_dispute_order_list: [], //未处理售后
        exprress_list:[]

    };

    function query_dispute_goods_order_list() {
        api.lorder.query_order_dispute_by_host_list({doing_type:0,step_status:0}).then(function (data) {

            html_data.un_dispute_page_index = data.result.page_index;
            html_data.un_dispute_page_count = data.result.page_count;
            _(data.result.list).each(function (item) {
                html_data.un_dispute_order_list.push(item);
            });
        })
    }
    function query_doing_dispute_goods_order_list() {
        api.lorder.query_order_dispute_by_host_list({step_status:[1, 2,31,32,33].join(',')}).then(function (data) {

            html_data.doing_dispute_page_index = data.result.page_index;
            html_data.doing_dispute_page_count = data.result.page_count;
            _(data.result.list).each(function (item) {
                html_data.doing_dispute_order_list.push(item);
            });
        })
    }
    function query_finish_dispute_goods_order_list() {
        api.lorder.query_order_dispute_by_host_list({step_status:[4].join(',')}).then(function (data) {

            html_data.finish_dispute_page_index = data.result.page_index;
            html_data.finish_dispute_page_count = data.result.page_count;
            _(data.result.list).each(function (item) {
                html_data.finish_dispute_order_list.push(item);
            });
        })
    }

    var app = new Vue({
            el: '#user_goods_order_page',
            data: html_data,
            methods: {
                price_filter: price_filter,
                show_head_img: show_head_img,
                query_dispute_goods_order_list: query_dispute_goods_order_list,
                query_doing_dispute_goods_order_list: query_doing_dispute_goods_order_list,
                query_finish_dispute_goods_order_list: query_finish_dispute_goods_order_list,



                imageClick:function(bigImgUrl) {
                    Magiclamp.mcImgPop(bigImgUrl);
                },
                open_payorder: function (payorder_id) {
                    location.href = 'pay.html?payorder_id=' + payorder_id;
                },

                open_dispute_order_info: function (goods_order_id) {

                    location.href = 'user_dispute_goods_orders.html?dispute_id=' + goods_order_id;

                    // Magiclamp.mcConfirm("提示", "确认投诉订单么？", null, function () {
                    //     api.lorder.dispute_goods_order({order_id: goods_order.id}).then(function (data) {
                    //         Magiclamp.mcAlert("提示", data.message);
                    //         app.get_order();
                    //     })
                    // });
                },
                query_order_dispute_by_host_list:function () {

                },
                dispute_goods_order_item: function (goods_item) {

                    location.href = 'user_create_dispute_order.html?goods_order_item_id=' + goods_item.id;

                    // Magiclamp.mcConfirm("提示", "确认投诉订单么？", null, function () {
                    //     api.lorder.dispute_goods_order({order_id: goods_order.id}).then(function (data) {
                    //         Magiclamp.mcAlert("提示", data.message);
                    //         app.get_order();
                    //     })
                    // });
                },

                make_goods_order: function (goods_order) {
                    api.lorder.confirm_goods_received({goods_order_id: goods_order.id}).then(function (data) {
                        app.get_order();
                        Magiclamp.mcAlert("提示", data.message);
                    });
                },


                close_page: function () {
                    ttjd.close_phonegap();
                },
                page_back: function () {
                    baseConfig.page_back();
                }
            }
        })
    ;

    html_data.sessionid = GetQueryString('sessionid');
    if (html_data.sessionid) {
        html_data.sessionid_q = "sessionid=" + html_data.sessionid;
        client_storage('sessionid', html_data.sessionid);
    }

    query_dispute_goods_order_list();
    query_doing_dispute_goods_order_list();
    query_finish_dispute_goods_order_list();
    setTimeout(function () {
        var $tags = $('#order-tab').find('a');
        window.mySwipe = new Swipe(document.getElementById('slider'), {
            continuous: false,
            disableScroll: false,
            stopPropagation: false,
            callback: function (index) {
                $tags.eq(index).addClass('tag-on')
                    .siblings('a').removeClass('tag-on');
            },
            transitionEnd: function (index, elem) {
            }
        });
        $tags.eq(0).click(function (e) {
            mySwipe.slide(0);
            e.preventDefault();
        });
        $tags.eq(1).click(function (e) {
            mySwipe.slide(1);
            e.preventDefault();
        });
        $tags.eq(2).click(function (e) {
            mySwipe.slide(2);
            e.preventDefault();
        });
        $tags.eq(3).click(function (e) {
            mySwipe.slide(3);
            e.preventDefault();
        });
    }, 1000);
});
